<?php
class Calendar_Form_ReservationAdd extends Zend_Dojo_Form {
	public function init() {
		$this->setMethod('post');

		$this->setDecorators(array(
			'FormElements',
            array('TabContainer', array(
                'id' => 'tabContainer',
                'style' => 'width: 100%; height: 500px;',
                'dijitParams' => array(
                    'tabPosition' => 'left'
                ),
            )),
            'Dojo_ValidateOnSubmit',
            'DijitForm',
        ))
        ->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
        
       	$this->addElement('SubmitButton','action', array('ignore' => true,'label'=>'Dodaj'));

		$subForm = $this->_getContentForm();
        $this->addSubForm($subForm, 'contenttab');
	}
	
	public function getValues($suppressArrayNotation = false) {
        $values = array();
        foreach ($this->getElements() as $key => $element) {
            if (!$element->getIgnore()) {
                $values[$key] = $element->getValue();
            }
        }
        foreach ($this->getSubForms() as $key => $subForm) {
            /*$fValues = $this->_attachToArray($subForm->getValues(true), $subForm->getElementsBelongTo());*/
            $values = array_merge($values, $subForm->getValues(true));
        }

        if (!$suppressArrayNotation && $this->isArray()) {
            $values = $this->_attachToArray($values, $this->getElementsBelongTo());
        }

        return $values;
    }

	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getContentForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'contenttab',
            'legend' => 'Rezerwacja',
        ));
        $subForm->addElement(
                'ValidationTextBox',
                'name',
                array(
                    'label' => 'Nazwa rezervacji',
                    'required'  => true,
                )
            )
            ->addElement(
                'DateTextBox',
                'from',
                array(
                    'value' => date('Y-m-d'),
                    'label' => 'Od',
                    'required'  => true,
                	'onChange' => 'dijit.byId("contenttab-to").constraints.min = arguments[0]'
                )
            )
            ->addElement(
                'DateTextBox',
                'to',
                array(
                    'label' => 'Do',
                    'required'  => true,
                	'onChange' => 'dijit.byId("contenttab-from").constraints.max = arguments[0]'
                )
            );

        return $subForm;
    }
}